﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace KC.DataAccess.Hub
{
    public static class utils
    {
        public static DataTable GetPostManagerPosts()
        {
            return CallSql(ConfigurationManager.ConnectionStrings["Hub"].ConnectionString, "GetEditorPages", true);
        }
        public static DataTable CallSql(string ConnectionString, string cmd, bool isSproc)
        {
            using (SqlConnection sc = new SqlConnection(ConnectionString))
            using (SqlCommand comm = new SqlCommand())
            {
                comm.Connection = sc;
                comm.CommandType = isSproc ? System.Data.CommandType.StoredProcedure : CommandType.Text;
                comm.CommandText = cmd;

                using (SqlDataAdapter da = new SqlDataAdapter(comm))
                using (DataTable dt = new DataTable())
                {
                    try
                    {
                        da.Fill(dt);
                        return dt;
                    }
                    catch (Exception ex) { throw new ApplicationException("SQL Server is Down", ex); }
                }
            }
        }
    }
}